mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-01 02:03:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <p>You are given a string <code>num</code> consisting of digits only.</p>
 | |
| 
 | |
| <p>Return <em>the <strong>largest palindromic</strong> integer (in the form of a string) that can be formed using digits taken from </em><code>num</code>. It should not contain <strong>leading zeroes</strong>.</p>
 | |
| 
 | |
| <p><strong>Notes:</strong></p>
 | |
| 
 | |
| <ul>
 | |
| 	<li>You do <strong>not</strong> need to use all the digits of <code>num</code>, but you must use <strong>at least</strong> one digit.</li>
 | |
| 	<li>The digits can be reordered.</li>
 | |
| </ul>
 | |
| 
 | |
| <p> </p>
 | |
| <p><strong class="example">Example 1:</strong></p>
 | |
| 
 | |
| <pre>
 | |
| <strong>Input:</strong> num = "444947137"
 | |
| <strong>Output:</strong> "7449447"
 | |
| <strong>Explanation:</strong> 
 | |
| Use the digits "4449477" from "<u><strong>44494</strong></u><u><strong>7</strong></u>13<u><strong>7</strong></u>" to form the palindromic integer "7449447".
 | |
| It can be shown that "7449447" is the largest palindromic integer that can be formed.
 | |
| </pre>
 | |
| 
 | |
| <p><strong class="example">Example 2:</strong></p>
 | |
| 
 | |
| <pre>
 | |
| <strong>Input:</strong> num = "00009"
 | |
| <strong>Output:</strong> "9"
 | |
| <strong>Explanation:</strong> 
 | |
| It can be shown that "9" is the largest palindromic integer that can be formed.
 | |
| Note that the integer returned should not contain leading zeroes.
 | |
| </pre>
 | |
| 
 | |
| <p> </p>
 | |
| <p><strong>Constraints:</strong></p>
 | |
| 
 | |
| <ul>
 | |
| 	<li><code>1 <= num.length <= 10<sup>5</sup></code></li>
 | |
| 	<li><code>num</code> consists of digits.</li>
 | |
| </ul>
 |